<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>客户列表</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<script type="text/javascript">
    var grid = null;
    var cstRlFlag = '${cstRlFlag}';
    $(function () {
        initForm();
        setCstClTypCd();
        initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
        searchBtnEvent();
        clearBtnEvent();
    });
    //选择担保人时，设置客户属性不可选
    function setCstClTypCd() {
        var cstRlFlag = '${cstRlFlag}';
        var cstTypCdNp = ProjectConstant.CST_TYP_CD_NP;
        var cstTypCd = '${cstTypCd}';
        if(StringUtils.isNotEmpty(cstTypCd)){
            $("#cstTypCd").val(cstTypCd);
        }
        if (cstTypCd == cstTypCdNp) {
            var slt=liger.get("cstTypCd");
            slt.setDisabled();
            slt.setValue(cstTypCd);
            $("#cstTypCd").val(cstTypCd);
        }
    }

    //清空按钮事件
    function clearBtnEvent() {
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();  //重置 input-text
            var form = liger.get("searchBar");
            form.setData({  //重置select等特殊表单
                "cstTypCd": " ",
                "cstNm": " "
                //  "cstRlTyp":" ",
            });
        });
    }

    //初始化表单
    function initForm() {
        $("#searchBar").ligerForm();
    }

    //查询按钮事件
    function searchBtnEvent() {
        $("#searchBtn").click(function (event) {
            var form = new liger.get("searchBar");
            var data = form.getData();
            data["crtTm"] = $("#crtTm").val();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            ;
            grid.reload();
        });
    }

    //查询参数
    function getSearchParams() {
        var form = new liger.get("searchBar");
        var data = form.getData();
        data["cstRlTyp"] = '${cstRlFlag}';
        var cstTypCd = '${cstTypCd}';
        if (cstTypCd) {
            data["cstTypCd"] = cstTypCd;
        }
        return data;
    }

    //初始化列表
    function initGrid() {
        var str1 = "";
        var str2 = "";
        if (cstRlFlag == ProjectConstant.CST_RL_CST) {
            str1 = "客户名称";
            str2 = "客户类型";
        }
        if (cstRlFlag == ProjectConstant.CST_RL_SPONSOR) {
            str1 = "担保人名称";
            str2 = "担保人类型";
        }
        $("#ligergrid1").ligerGrid({
            url: '<%=path%>/customer/cstbscinfo/initList.do',
            method: 'get',
            parms: getSearchParams(),
            columns: [
                /*      { display: '客户性质', name: 'cstStsCdNm', minWidth: 60, enabledSort:true },
                 { display: '客户级别', name: 'cstLvlCdNm', minWidth: 60 , enabledSort:true}, */
                {display: str1, name: 'cstNm', minWidth: 100, enabledSort: true},
                {display: str2, name: 'cstTypCdNm', width: 60, enabledSort: true},
                {display: '证件/组织机构代码', name: 'certNo', minWidth: 200, enabledSort: true},
                {
                    display: '操作',
                    isSort: false,
                    width: 100,
                    render: function (rowdata, rowindex, value) {
                        var h = '<a class="sq-button-hasicon" href="javascript:chooseCstRow(';
                        h += "'" + rowdata.id + "',";
                        h += "'" + rowdata.cstNm + "',";
                        h += "'" + rowdata.cstTypCd + "',";

                        h += "'" + rowdata.cstStsCdNm + "',";
                        h += "'" + rowdata.cstLvlCdNm + "',";
                        h += "'" + rowdata.cstTypCdNm + "',";
                        h += "'" + rowdata.certNo + "',";
                        h += "'" + rowdata.crtTm + "',";
                        h += "'" + rowdata.certTypCd + "',";
                        if(rowdata.cstTypCd == ProjectConstant.CST_TYP_CD_NP){
                            h += "'" + rowdata.cstNpBscInfoVO.certValidSDt + "',";
                            h += "'" + rowdata.cstNpBscInfoVO.certValidEDt + "'";
                        }else{
                            h += "'',";
                            h += "''";
                        }
                        h += ')"><i class="sqBtnIco_3"></i>选择</a>'
                        return h;
                    }
                }
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: false,
            rownumbers: true
        });
        grid = liger.get("ligergrid1");
        grid.setHeight(100);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }


    function clearBtn() {
        var form = new liger.get("searchBar");
        form.clear();
    }

    function iframeResize() {
        if (parent.mainApp) {
            parent.mainApp.parentTab.onResize();
        }
        ;
    }
    function chooseCstRow(id, name, cstType, cstStsCdNm, cstLvlCdNm, cstTypCdNm, certNo, crtTm,certTypCd,certValidSDt,certValidEDt) {
        var cstRlFlag = '${cstRlFlag}';
        var cstRlCd = ProjectConstant.CST_RL_SPONSOR;
        if (cstRlFlag == cstRlCd) {
            if (id) {
                //查询客户自然人的基础信息 todo 为啥再查一遍客户信息
                var _url = '<%=path%>/customer/cstbscinfo/getShowDetailById.do';
                $.ajax({
                    type: 'get',
                    dataType: 'json',
                    data: {id: id},
                    url: _url,
                    success: function (msg) {
                        if (msg.success == 1) {
                            // parent.window.document.getElementById("cstNm").value = name;
                            // parent.window.document.getElementById("cstTypCd").value = cstType;
                            // parent.window.document.getElementById("cstStsCdNm").value = cstStsCdNm;
                            // parent.window.document.getElementById("cstLvlCdNm").value = cstLvlCdNm;
                            // parent.window.document.getElementById("cstTypCdNm").value = cstTypCdNm;
                            // parent.window.document.getElementById("certNo").value = certNo;
                            // parent.window.document.getElementById("crtTm").value = crtTm;

                            var guarList = [];
                            var guar = {};
                            guar.cstId = id;
                            guar.cstNm = name;
                            guar.cstTypCd = cstType;
                            guar.certNo = certNo;
                            /*  if(msg.data.cstTypCd=ProjectConstant.CST_TYP_CD_NP){
                             guar.mp1 = msg.data.cstNpBscInfoVO.mp1;
                             guar.genderCd = msg.data.cstNpBscInfoVO.genderCd;
                             }; */
                            guarList.push(guar);
                            var cstTypCd = cstType;
                            if (cstTypCd && cstTypCd == ProjectConstant.CST_TYP_CD_NP) {
                                parent.window.addNpSelect(guarList, msg.data.cstTypCd);
                                try {
                                    parent.liger.get("npligergrid").reload();
                                }catch(e){console.info(e);}
                                frameElement.dialog.close();
                            }
                            if (cstTypCd && cstTypCd == ProjectConstant.CST_TYP_CD_LP) {
                                parent.window.addLpSelect(guarList, msg.data.cstTypCd);
                                try {
                                    parent.liger.get("lpligergrid").reload();
                                }catch(e){console.info(e);}
                                frameElement.dialog.close();
                            }

                            /* 	if(!id){
                             top.$.ligerDialog.SQalert({content: LogUtils.LOG_PRJ_CST_SELECT_BEFORE,SQ_type: "warning"});
                             return false; //验证不通过，不执行以下代码
                             //
                             }else{
                             parent.window.addRow();
                             }
                             parent.$.ligerDialog.close();
                             parent.$(".l-dialog,.l-window-mask").css("display","none");  */
                        }
                    }
                });
            }
        } else if (cstRlFlag == ProjectConstant.CST_RL_CST) {
            parent.window.document.getElementById("cstId").value = id;
            parent.window.document.getElementById("certNo").value = certNo;
            parent.window.document.getElementById("certTypCd").value = certTypCd;
            if(!certValidSDt||certValidSDt=='null'){
                certValidSDt='';
            }
            if(!certValidEDt||certValidEDt=='null'){
                certValidEDt='';
            }
            parent.window.document.getElementById("certValidSDt").value = certValidSDt;
            parent.window.document.getElementById("certValidEDt").value = certValidEDt;
            parent.window.document.getElementById("cstTypCd").value = cstType;

            /*var nm = parent.window.document.getElementById("cstNm");
            $(nm).html(name);*/
            //验证客户是否有必填项没有填写
            <%--     	var _url = '<%=path%>/project/prjbscinfo/checkCstRequiredField.do';
                    $.ajax({
                        type: 'get',
                        dataType:'json',
                        data:{cstId:id},
                        url: _url,
                        success:function(msg){
                             if(msg.success != 1){
                                 top.$.ligerDialog.SQalert({content: "客户："+name+"有必填信息未维护！",SQ_type: "error"});
                                 return false;
                             }else{
                                    var nm = parent.window.document.getElementById("cstNm");
                                    $(nm).html(name);
                                    var div =  parent.window.document.getElementById("cstNmDiv");
                                    $(div).show();
                                parent.$.ligerDialog.close();
                                parent.$(".l-dialog,.l-window-mask").css("display","none");
                             }
                        }
                    }); --%>
            var nm = parent.window.document.getElementById("cstNm");
            $(nm).html(name);
            var div = parent.window.document.getElementById("cstNmDiv");
            $(div).show();
            var addPrjPage = parent.window.document.getElementById("addPrjPage").value;
            if (addPrjPage && addPrjPage == '1') {
                parent.window.queryCstCreditiInvest();
            }
         // ==== start 自动带出客户响应的四要素信息   银行账号、预留手机号   lihaiyang
            $.ajax({
                       type: 'GET',
                       dataType:'json',
                       data:{'cstId':id},
                       async : false,
                       url: '<%=path%>/project/prjCstAccInfo/getPrjCstAccInfo.do',
                       success:function(msg){
                            if(msg.success == 1){
                           	 //parent.window.document.getElementById("bkNo").value = msg.data.bkNm;
                           	 parent.window.document.getElementById("accNo").value = msg.data.accNo;
                                parent.window.document.getElementById("mp").value = msg.data.mp;
                                if(parent.$("#accNo").val() != null && parent.$("#accNo").val().length>0){
                                    parent.$("#accNo").attr("disabled","disabled");
                                    parent.$("#mp").attr("disabled","disabled");
                               }
                            }else{
                           	 parent.window.document.getElementById("accNo").value = "";
                                parent.window.document.getElementById("mp").value = "";
                                parent.$("#accNo").removeAttr("disabled");
                                parent.$("#mp").removeAttr("disabled");
                            }
                       },
                       error:function(msg){
                       	alert("同步请求客户银行账号信息错误");
                       }
                   });
           // ==== end
            frameElement.dialog.close();
            //parent.$.ligerDialog.close();
            //parent.$(".l-dialog,.l-window-mask").css("display", "none");
        } else {
            //紧急联系人
            parent.window.document.getElementById("cstId").value = id;
            parent.window.document.getElementById("cstNm").value = name;
            parent.window.document.getElementById("cstTypCd").value = cstType;
            parent.window.document.getElementById("cstStsCdNm").value = cstStsCdNm;
            parent.window.document.getElementById("cstLvlCdNm").value = cstLvlCdNm;
            parent.window.document.getElementById("cstTypCdNm").value = cstTypCdNm;
            parent.window.document.getElementById("certNo").value = certNo;
            parent.window.document.getElementById("crtTm").value = crtTm;
            var urgentPrjLinkMan = [];
            var urgent = {};
            urgent.cstId = id;
            urgent.cstNm = name;
            urgent.cstTypCd = cstTypCd;
            urgent.certNo = certNo;
            urgentPrjLinkMan.push(urgent);
            parent.window.saveSelectUrgentPrjLinkMan(urgentPrjLinkMan);
            //parent.liger.get("urgentPrjLinkManGrid").reload();
            frameElement.dialog.close();
            //parent.urgentPrjLinkManGrid.reload();

        }
        // parent.grid.reload();
    }
</script>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">客户名称:</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">客户类型:</div>
                    <div class="field">
                        <select name="cstTypCd" id="cstTypCd">
                            <option value=" " seleted>请选择</option>
                            <c:forEach items="${searchSelectCsttypcdlist }" var="csttypcd">
                                <option value="${csttypcd.key }">${csttypcd.value }</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <%--      <div class="fieldBox">
                         <div class="label">客户属性</div>
                         <div class="field">
                             <select name="cstRlTyp" id="cstRlTyp">
                                <option value=" ">请选择</option>
                                <c:forEach items="${cstRlTypCdList }" var="cstRlcd">
                                        <c:if test="${currentCstRlType == cstRlcd.key }">
                                            <option value="${cstRlcd.key }" selected>${cstRlcd.value }</option>
                                        </c:if>
                                     <c:if test="${currentCstRlType != cstRlcd.key }">
                                            <option value="${cstRlcd.key }">${cstRlcd.value }</option>
                                        </c:if>
                                </c:forEach>
                             </select>
                         </div>
                     </div> --%>
                <%--  <div class="fieldBox">
                     <div class="label">所属机构</div>
                     <div class="field">
                         <select name="buOrgCd" id="buOrgCd">
                             <option value=" " seleted>请选择</option>
                             <c:forEach items="${orgListList }" var="org">
                                 <c:if test="${currentBuOrgCd == org.key }">
                                     <option value="${org.key }" selected>${org.value }</option>
                                 </c:if>
                                 <c:if test="${currentBuOrgCd != org.key }">
                                     <option value="${org.key }">${org.value }</option>
                                 </c:if>
                             </c:forEach>
                         </select>
                     </div>
                 </div> --%>
                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_1"></i> -->查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_19"></i> -->清空</span>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>
</div>
</body>
</html>